/*
* comment.h - This file is the part of the wp-notifier.(code name "luan luan")
* Copyright (C) 2010 Dean Lee <deanlee3@gmail.com>, http://www.deanlee.cn
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
* 
* Acknowledgements:
*   <> Many thanks to all of you, who have encouraged me to update my articles
*     and code, and who sent in bug reports and fixes.
* 
*/
#ifndef _COMMENT_H
#define _COMMENT_H
#include <QSharedData>
#include <QString>
#include <QDateTime>
class CommentData : public QSharedData
{
public:
	enum CommentStatus{approve, hold, spam, trash};
	CommentData()
	{
		m_comment_id = m_user_id = m_comment_parent = m_post_id = m_read_flag = 0;
		m_status = approve;
		m_unread = false;
	}

	CommentData(const CommentData& other) : QSharedData(other)
	{
		m_comment_id = other.m_comment_id;
		m_user_id = other.m_user_id;
		m_comment_parent = other.m_comment_parent;
		m_status = other.m_status;
		m_content = other.m_content;
		m_link = other.m_link;
		m_post_id = other.m_post_id;
		m_post_title = other.m_post_title;
		m_author = other.m_author;
		m_author_url = other.m_author_url;
		m_author_email = other.m_author_email;
		m_author_ip = other.m_author_ip;
		m_dateCreated = other.m_dateCreated;
		m_dateDiff = other.m_dateDiff;
		m_unread = other.m_unread;
		m_read_flag = other.m_read_flag;
	}
	~CommentData()
	{
	}
	int m_comment_id;
	int m_user_id;
	int m_comment_parent;
	CommentData::CommentStatus m_status;
	QString m_content;
	QString m_link;
	int m_post_id;
	QString m_post_title;
	QString m_author;
	QString m_author_url;
	QString m_author_email;
	QString m_author_ip;
	QDateTime m_dateCreated;
	QString m_dateDiff;
	bool m_unread;
	bool m_read_flag;
};

class Comment
{
public:

	Comment();
	Comment(const Comment& other);
	~Comment(){}
	int id()const{return d->m_comment_id;}
	int userId()const{return d->m_user_id;}
	int parentId()const{return d->m_comment_parent;}
	CommentData::CommentStatus status()const{return d->m_status;}
	QString content()const{return d->m_content;}
	QString link()const{return d->m_link;}
	int postId()const{return d->m_post_id;}
	QString postTitle()const{return d->m_post_title;}
	QString author()const{return d->m_author;}
	QString authorUrl()const{return d->m_author_url;}
	QString authorEmail()const{return d->m_author_email;}
	QString authorIp()const{return d->m_author_ip;}
	QDateTime dateCreated()const{return d->m_dateCreated;}
	QString dateDiff()const{return d->m_dateDiff;}
	bool unread()const{return d->m_unread;}

	void setUnread(bool b){d->m_unread = b;}
	void setStatus(CommentData::CommentStatus s){d->m_status = s;}
	void setContent(const QString& c){d->m_content = c;}

	//static QList<Comment*> responseToCommentList(const QVariant& response);
	bool fromMap(const QVariant& map);
	static CommentData::CommentStatus stringToStatus(const QString& status);
	static QString statusToString(CommentData::CommentStatus status);
protected:
	QSharedDataPointer<CommentData> d;

};

#endif